/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import bean.Subject;
import javax.swing.JList;
import myUI.ArrayListModel;

/**
 *
 * @author Administrator
 */
public class JlistUtil {
    
    public static void left(JList leftList,JList rightList){
        int selected=leftList.getSelectedIndex();
        if(selected<0)
            return;
        Object subject=leftList.getSelectedValue();
        ArrayListModel leftModel=(ArrayListModel)leftList.getModel();
        leftModel.removeElement(subject);
       
       ArrayListModel rightModel=(ArrayListModel)rightList.getModel();
       rightModel.addElement(subject);
    }
    
    public static void right(JList leftList,JList rightList){
         int selected=rightList.getSelectedIndex();
        if(selected<0)
            return ;
        Object subject=rightList.getSelectedValue();
        ArrayListModel rightModel=(ArrayListModel)rightList.getModel();
        rightModel.removeElement(subject);
       
       ArrayListModel leftModel=(ArrayListModel)leftList.getModel();
       leftModel.addElement(subject);
    }
    
    public static void shiftUp(JList jList){
        int selectd=jList.getSelectedIndex();
        ArrayListModel model=(ArrayListModel)jList.getModel();
        model.shiftUp(selectd);
    }
    
    public static void shiftDown(JList jList){
        int selectd=jList.getSelectedIndex();
        ArrayListModel model=(ArrayListModel)jList.getModel();
        model.shiftDown(selectd);
    }
}
